package com.hex.ds.hdtp.core.app.data.table.service.impl;

import com.hex.ds.hdtp.core.app.common.page.PageData;
import com.hex.ds.hdtp.core.app.common.page.converter.IPageAndPageDtoConverter;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.data.table.converter.ITableTransferRunLogConverter;
import com.hex.ds.hdtp.core.app.data.table.dto.request.TableTransferRunLogRequestDto;
import com.hex.ds.hdtp.core.app.data.table.dto.response.TableTransferRunLogResponseDto;
import com.hex.ds.hdtp.core.app.data.table.service.ITableTransferRunLogService;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.data.table.po.TableTransferRunLogPo;
import com.hex.ds.hdtp.core.inf.data.table.repository.ITableTransferRunLogRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.app.data.table.service.impl
 * @ClassName TableTransferTaskService
 * @Description 表迁移任务-业务接口实现
 * @Author Wang zhihao
 * @Date 2023/8/8 18:40
 * @Version v1.0
 **/
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TableTransferRunLogService implements ITableTransferRunLogService {

    private final ITableTransferRunLogRepository tableTransferRunLogRepository;

    private final ITableTransferRunLogConverter converter;

    private final IPageAndPageDtoConverter pageAndPageDtoConverter;

    /**
     * @Method queryListByPage
     * @Param
     * @param tableTransferRunLogRequestDto
     * @param pageDto
     * @Return com.hex.ds.hdtp.core.app.common.page.PageData
     * @Description 表迁移执行记录-分页查询
     * @Author Wang zhihao
     * @Date 2023/8/9 14:31
     * @Version V1.0
     */
    @Override
    public PageData queryListByPage(TableTransferRunLogRequestDto tableTransferRunLogRequestDto, PageDto pageDto) {
        final Page<TableTransferRunLogPo> pageResult = tableTransferRunLogRepository.queryListByPage(
                converter.toTableTransferRunLogPo(tableTransferRunLogRequestDto), pageAndPageDtoConverter.toPage(pageDto));
        List<TableTransferRunLogResponseDto> responseDtos = converter.toTableTransferRunLogResponseDtoList(pageResult.getData());
        return new PageData(responseDtos, pageResult.getTotal());
    }

    /**
     * @Method add
     * @Param
     * @param tableTransferRunLogRequestDto
     * @Return void
     * @Description 表迁移执行记录-新增
     * @Author Wang zhihao
     * @Date 2023/8/9 14:31
     * @Version V1.0
     */
    @Override
    public void add(TableTransferRunLogRequestDto tableTransferRunLogRequestDto) {
        int count = tableTransferRunLogRepository.add(converter.toTableTransferRunLogPo(tableTransferRunLogRequestDto));
        if (count != 1) {
            throw new RuntimeException("新增表迁移执行记录失败");
        }
    }

    /**
     * @Method modifyById
     * @Param
     * @param tableTransferRunLogRequestDto
     * @Return void
     * @Description 表迁移执行记录-根据主键修改
     * @Author Wang zhihao
     * @Date 2023/8/9 14:33
     * @Version V1.0
     */
    @Override
    public void modifyById(TableTransferRunLogRequestDto tableTransferRunLogRequestDto) {
        int count = tableTransferRunLogRepository.modifyById(converter.toTableTransferRunLogPo(tableTransferRunLogRequestDto));
        if (count != 1) {
            throw new RuntimeException("修改表迁移执行记录失败");
        }
    }

    /**
     * @Method removeById
     * @Param
     * @param pkId
     * @Return void
     * @Description 表迁移执行记录-根据主键删除
     * @Author Wang zhihao
     * @Date 2023/8/9 14:33
     * @Version V1.0
     */
    @Override
    public void removeById(String pkId) {
        int count = tableTransferRunLogRepository.removeById(pkId);
        if (count != 1) {
            throw new RuntimeException("删除表迁移执行记录失败");
        }
    }

}
